﻿using LibNiconico.NiconicoApi.Extentions;
using LibNiconico.NiconicoApi.Internal;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LibNiconico.NiconicoApi.Mylist
{
    /// <summary>
    /// ニコニコマイリスト追加実行問い合わせ情報
    /// </summary>
    public  class NicoMylistAddExecuteQueryInfo : NicoUrlEncodedPostAble
    {

        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="mylistItem"></param>
        /// <param name="response"></param>
        public NicoMylistAddExecuteQueryInfo(NicoMylistItem mylistItem, NicoMylistAddRequestResponse response) : this(mylistItem.Id, response.ItemType, response.ItemId, response.Token) { }

        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="groupId"></param>
        /// <param name="itemType"></param>
        /// <param name="itemId"></param>
        /// <param name="token"></param>
        private NicoMylistAddExecuteQueryInfo(string groupId, string itemType, string itemId, string token) : this(groupId, itemType, itemId,"", token) { }

        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="groupId"></param>
        /// <param name="itemType"></param>
        /// <param name="itemId"></param>
        /// <param name="description"></param>
        /// <param name="token"></param>
        private NicoMylistAddExecuteQueryInfo(string groupId, string itemType, string itemId, string description, string token)
        {
            GroupId = groupId;
            ItemType = itemType;
            ItemId = itemId;
            Description = description;
            Token = token;
        }

        /// <summary>
        /// グループID
        /// </summary>
        public string GroupId { get; set; }

        /// <summary>
        /// アイテムタイプ
        /// </summary>
        public string ItemType { get; set; }

        /// <summary>
        /// アイテムID
        /// </summary>
        public string ItemId { get; set; }

        /// <summary>
        /// 詳細
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// トークン
        /// </summary>
        public string Token { get; set; }

        /// <summary>
        /// ポスト用データ取得
        /// </summary>
        /// <returns></returns>
        internal override byte[] AsPostData()
        {
            MemoryStream stream = new MemoryStream();
            QueryStrings querys = new QueryStrings();
            querys.Add("group_id", GroupId);
            querys.Add("item_type", ItemType);
            querys.Add("item_id", ItemId);
            querys.Add("description", Description);
            querys.Add("token", Token);

            using (StreamWriter writer = new StreamWriter(stream))
            {
                 writer.Write(querys.ToString());
            }

            return stream.ToArray();
        }

        /// <summary>
        /// URLパスとして取得
        /// </summary>
        /// <returns></returns>
        internal override string AsPath()
        {
            return "api/mylist/add";
        }

        /// <summary>
        /// URL問い合わせ文字列として取得
        /// </summary>
        /// <returns></returns>
        internal override string AsQuery()
        {
            return "";
        }
    }
}
